using System.Xml;

namespace ServiceModel.Syndication.LEAP2A {
    /// <summary>
    /// Represents personal and organisational data which uses a country code
    /// See http://wiki.cetis.ac.uk/2009-03/LEAP2A_personal_data for more details
    /// </summary>
    public class LeapCountryData : LeapDataItem {
        /// <summary>
        /// Gets or sets the country code.
        /// </summary>
        /// <value>The country code.</value>
        public string CountryCode {
            get;
            set;
        }

        protected override void WriteAttributes(XmlWriter writer, LeapFeed feed) {
            base.WriteAttributes(writer, feed);

            if (!string.IsNullOrEmpty(CountryCode)) {
                writer.WriteAttributeString(
                    feed.LeapPredicatesNamespacePrefix,
                    "countrycode",
                    feed.LeapPredicatesNamespace,
                    CountryCode);
            }
        }

        protected override bool TryParseElement(XmlReader reader) {
            if (reader.LocalName == "persondata" || reader.LocalName == "orgdata") {
                this.CountryCode = reader.GetAttribute(reader.Prefix + ":countrycode");
            }

            return base.TryParseElement(reader);
        }
    }
}
